package com.cy.pj.module.controller;

import com.cy.pj.module.pojo.ResponseResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/*不再将响应结果理解为view，
    并将响应结果转换为json格式（前提是必须满足转换Json格式数据条件），
    写到响应体，响应到客户端*/
@Controller
public class JsonObjectController {
    @RequestMapping("/doConvertResponseToJson")
    @ResponseBody
    public ResponseResult doConvertResponseToJson(){
        ResponseResult result=new ResponseResult();
        result.setCode(200);
        result.setMessage("OK");
        return result;
    }
    @RequestMapping("/doConvertMapToJson")
    @ResponseBody
    public Map<String,Object> doConvertMapToJson(){
        Map<String,Object> map=new HashMap<>();
        map.put("username","刘德华");
        map.put("state",true);
        return map;
    }
}
